﻿var url = new Url();
var $css = url.GetQueryString("css");
var serializer = new JSONSerializer();
var $Id = url.GetQueryString("id");

if ($Id) {//编辑模式，获取并绑定权限信息
    $.getJSON("../Handler/PageRightHandler.ashx", { PageId: $Id, Type: 5, _: Math.random() }, function (result) {
        if (result.Status) {
            serializer.DeSerialize($("#formArea")[0], result.Data);
        } else {
            alert(result.Message);
        }
    });
}
$("#roleNameList").focus(function () { $('#myModal').modal('show'); });
//全选
$("#selectAll").change(function () {
    $("#roleTree :checkbox").each(function (index, item) {
        $(this)[0].checked = $("#selectAll")[0].checked;
    });
});
//反选
$("#selectInvert").click(function () {
    $("#roleTree :checkbox").each(function (index, item) {
        $(this)[0].checked = !$(this)[0].checked;
    });
});
//不选
$("#selectNone").click(function () {
    $("#roleTree :checkbox").each(function (index, item) {
        $(this)[0].checked = false;
    });
});

$("#formArea .text").change(function () {
    var name = $(this).prev("label").text();
    var text = $(this).val() ? "" : name + "不能为空";
    $(this).siblings(".error").text(text);
});
//保存
$("#btnSave").click(function () {
    var errorDom;
    $("#formArea .text").each(function (index, item) {
        if (!$(this).val()) {
            errorDom = $(this);
            errorDom.change();
            return false;
        }
    })
    if (errorDom) {
        return;
    }
    var $formData = serializer.Serialize($("#formArea")[0]);
    $formData._=Math.random();
    if ($Id) {
        $formData.Type = 2;
    }
    $.getJSON("../Handler/PageRightHandler.ashx", $formData, function (result) {
        alert(result.Message);
        if (result.Status) {
            window.history.back();
        }
    })
});

$("#pageType").change(function () {
    if ($(this).val()==="True") {
        $("#eidtRight").val(0).attr("disabled", "true");
    } else {
        $("#eidtRight").val("").removeAttr("disabled").focus();
    }
}).change();
